﻿using AutoMapper;
using J.Status.Application.Command.BookingCommand;
using J.StatusModel;
using MediatR;
using StatusService;

namespace J.Status.Application.Handler.BookingHandler
{
    public class BookingCreateHandler : IRequestHandler<BookingCreateCommand, int>
    {
        private readonly IMapper mapper;
        private readonly IBookingService service;

        public BookingCreateHandler(IBookingService service, IMapper mapper)
        {
            this.service = service;
            this.mapper = mapper;
        }

        public async Task<int> Handle(BookingCreateCommand request, CancellationToken cancellationToken)
        {
            BookingModel model = mapper.Map<BookingModel>(request);
            return await service.AddBooking(model);
        }
    }
}
